<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;
var tavernId = null;
var gettavernUrl = "/tavern/get/";
var edittavernUrl = "/tavern/edit/";
var currenttavern = null;
$(document).ready(function() {
	tavernId = window.dialogArguments;
	$.ajax({
		   type: "GET",
		   url: gettavernUrl,
		   data: "tavernId=" + tavernId,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   var result = data.result;
				   $("#tavernId").val(result.tavernId);
				   $("#deployId").val(result.deployId);
				   $("#level").val(result.level);
				   $("#requiredLevel").val(result.requiredLevel);
				   $("#moneyType").val(result.moneyType);
				   $("#money").val(result.money);
				   $("#npcRates").val(result.npcRates);
				   $("#taskRates").val(result.taskRates);
				   				   
				   currenttavern = result; 
				   listselectors();
				   window.returnValue=1;
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
});

function listselectors() {
}

function edittavern() {
	var tavernIdParam = "tavernId=" + tavernId;
	var levelValue = $("#level").val();
	if(!checkInteger("等级",levelValue,false)) {
		return;
	}
	var levelParam = "level=" + xparseInt(levelValue);
		
	var requiredLevelValue = $("#requiredLevel").val();
	if(!checkInteger("等级需求",requiredLevelValue,false)) {
		return;
	}
	var requiredLevelParam = "requiredLevel=" + xparseInt(requiredLevelValue);
		
	var moneyTypeValue = $("#moneyType").val();
	
	var moneyTypeParam = "moneyType=" + moneyTypeValue;
		
	var moneyValue = $("#money").val();
	if(!checkInteger("币值",moneyValue,false)) {
		return;
	}
	var moneyParam = "money=" + xparseInt(moneyValue);
		
	var npcRatesValue = $("#npcRates").val();
	
	var npcRatesParam = "npcRates=" + npcRatesValue;
		
	var taskRatesValue = $("#taskRates").val();
	
	var taskRatesParam = "taskRates=" + taskRatesValue;
			
	$.ajax({
		   type: "POST",
		   url: edittavernUrl,
		   		   data:  tavernIdParam + '&' +  levelParam  +'&'+   requiredLevelParam  +'&'+   moneyTypeParam  +'&'+   moneyParam  +'&'+   npcRatesParam  +'&'+   taskRatesParam  ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			   	   beforeWindowClose();
				   window.close();
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

	
	
	
	
			function addnpcRates() {
			var npcRatesstr = $("#npcRates").val();
			var returnCallback = function(retvalue) {
				$('#npcRates').val(retvalue);
			}
			openDialog("/pages/core/Array.html",["/pages/customer/NpcRefreshRate.html",npcRatesstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
			function addtaskRates() {
			var taskRatesstr = $("#taskRates").val();
			var returnCallback = function(retvalue) {
				$('#taskRates').val(retvalue);
			}
			openDialog("/pages/core/Array.html",["/pages/customer/TaskRefreshRate.html",taskRatesstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("tavern",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/tavern/add" method="post">
		<table>
			<tbody>
				<tr>
					<td>ID</td><td><input type="text" id="tavernId" name="tavernId" disabled/></td>
					<td>发布Id</td><td><input type="text" id="deployId" name="deployId" disabled/></td>
				</tr>
			</tbody>
		</table>
		<table>
			<tbody>				
					<tr>					<td>
						<label for="level" id="lbl_level">等级</label>
													<input type="text" id="level" name="level" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="requiredLevel" id="lbl_requiredLevel">等级需求</label>
													<input type="text" id="requiredLevel" name="requiredLevel" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="moneyType" id="lbl_moneyType">币型</label>
																				<select id="moneyType" name="moneyType">
								
									<option value="0">银币</option>
								
									<option value="1">金币</option>
															</select>
											</td>
									
										<td>
						<label for="money" id="lbl_money">币值</label>
													<input type="text" id="money" name="money" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="npcRates" id="lbl_npcRates">npc刷新规则</label>
													<input type="text" id="npcRates" name="npcRates" value="[]" disabled/>
							<input type="button" value="..." onclick="addnpcRates()"/>
											</td>
									
										<td>
						<label for="taskRates" id="lbl_taskRates">任务刷新规则</label>
													<input type="text" id="taskRates" name="taskRates" value="[]" disabled/>
							<input type="button" value="..." onclick="addtaskRates()"/>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="edittavern()" value="修改"/>
	</form>
	</div>
</body>